//
//  RootViewController.m
//  真·豆瓣半完全体
//
//  Created by dllo on 15/12/31.
//  Copyright © 2015年 lanou3g. All rights reserved.
//

#import "RootViewController.h"
#import "MyTableViewCell3.h"
#import "UIImageView+WebCache.h"
#import "RootViewController2.h"
@interface RootViewController ()<UITableViewDataSource, UITableViewDelegate>

@property (nonatomic, retain) UITableView *tableView;
@property (nonatomic, retain) NSMutableArray *arrData;

@property (nonatomic, retain) NSMutableDictionary *num2;
@end

@implementation RootViewController
- (void)dealloc{
    [_tableView release];
    [super dealloc];
}
- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        
    }
    return self ;
}



- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:84/255.0 green:139/255.0 blue:156/255.0 alpha:1];
    self.navigationController.navigationBar.translucent = NO;
    self.navigationItem.title = @"活动";
    
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 375, 554) style:UITableViewStylePlain];
    [self.view addSubview:_tableView];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    [_tableView release];
    
    [self dataHandle];
    [_tableView registerClass:[MyTableViewCell3 class] forCellReuseIdentifier:@"cell"];
    self.num2 = [NSMutableDictionary dictionary];
}

#pragma mark - TableViewDelegate
- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return _arrData.count;
}
- (CGFloat ) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 200;
}
- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    MyTableViewCell3 *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    
    cell.imgView.image = [UIImage imageNamed:[NSString stringWithFormat:@"bg_eventlistcell@2x.png"]];
    cell.label.text = [_arrData[indexPath.row] objectForKey:@"title"];
    cell.label1.text = [NSString stringWithFormat:@"%@--%@", [[_arrData[indexPath.row] objectForKey:@"begin_time"] substringWithRange:NSMakeRange(5, 11)], [[_arrData[indexPath.row] objectForKey:@"end_time"] substringWithRange:NSMakeRange(5, 11)]];
    cell.label2.text = [_arrData[ indexPath.row] objectForKey:@"address"];
    cell.label3.text = [NSString stringWithFormat:@"类型：%@", [_arrData[ indexPath.row] objectForKey:@"category_name"]];
    cell.label4.text = [NSString stringWithFormat:@"感兴趣：%@", [_arrData[indexPath.row] objectForKey:@"wisher_count"]];
    cell.label5.text = [NSString stringWithFormat:@"参加：%@", [_arrData[indexPath.row] objectForKey:@"participant_count"]];
//    cell.imgView2.image = [UIImage imageNamed:[NSString stringWithFormat:@"%ld.jpg", indexPath.row + 1]];
    cell.imgView3.image = [UIImage imageNamed:@"icon_date@2x.png"];
    cell.imgView4.image = [UIImage imageNamed:@"icon_spot@2x.png"];
    cell.imgView5.image = [UIImage imageNamed:@"icon_catalog@2x.png"];
    

    [cell.imgView2 sd_setImageWithURL:[NSURL URLWithString:_arrData[indexPath.row][@"image"]]];
    
    return cell;
}
/** TableView点击方法 */
- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    RootViewController2 *root2Vc = [[RootViewController2 alloc] init];
    root2Vc.name = [_arrData[indexPath.row] objectForKey:@"title"];
    root2Vc.time = [NSString stringWithFormat:@"%@--%@", [[_arrData[indexPath.row] objectForKey:@"begin_time"] substringWithRange:NSMakeRange(5, 11)], [[_arrData[indexPath.row] objectForKey:@"end_time"] substringWithRange:NSMakeRange(5, 11)]];
    NSMutableDictionary *dic = _arrData[indexPath.row][@"owner"];
    root2Vc.owner_name =dic[@"name"];
    root2Vc.category_name = [NSString stringWithFormat:@"类型：%@", [_arrData[ indexPath.row] objectForKey:@"category_name"]];
    root2Vc.address = [_arrData[ indexPath.row] objectForKey:@"address"];
    root2Vc.content = [_arrData[indexPath.row] objectForKey:@"content"];
    root2Vc.img = _arrData[indexPath.row][@"image"];
    
    root2Vc.title1 = _arrData[indexPath.row][@"title"];
    root2Vc.block = ^(NSString *str){
        [_num2 setObject:@"已收藏" forKey:str];
    };
    root2Vc.Num2 = _num2;
    [self.navigationController pushViewController:root2Vc animated:YES];
}














/** 数据解析 */
- (void)dataHandle{
    NSString *path = [[NSBundle mainBundle] pathForResource:@"activity" ofType:@"plist"];
     self.arrData = [NSMutableArray arrayWithContentsOfFile:path];
    

    
    
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
